package com.qiqidream.admin.system.model.dto;

import com.qiqidream.admin.common.entity.ApiPath;
import com.qiqidream.admin.common.enums.MenuType;
import com.qiqidream.admin.system.model.entity.Menu;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @author QiQiDream
 * @since 2019/12/5 16:16
 */
@Data
public class MenuDto {
    @ApiModelProperty(value = "id")
    private Long id;

    @ApiModelProperty(value = "父级id")
    private Long parentId;

    @ApiModelProperty(value = "路由地址")
    private String path;

    @ApiModelProperty(value = "重定向地址,在面包屑中点击会重定向去的地址")
    private String redirect;

    @ApiModelProperty(value = "菜单编码（开启缓存时,需要与组件名一致，不可重复）")
    private String code;

    @ApiModelProperty(value = "标题")
    private String title;

    @ApiModelProperty(value = "图标")
    private String icon;

    @ApiModelProperty(value = "组件路径")
    private String component;

    @ApiModelProperty(value = "是否不在左侧路由显示")
    private Boolean hidden;

    @ApiModelProperty(value = "是否缓存")
    private Boolean cache;

    @ApiModelProperty(value = "类型（'目录','菜单','按钮'）")
    private MenuType type;

    @ApiModelProperty(value = "排序")
    private Integer sort;

    @ApiModelProperty(value = "接口路径")
    private List<String> apiGetPath;

    @ApiModelProperty(value = "接口路径")
    private List<String> apiPutPath;

    @ApiModelProperty(value = "接口路径")
    private List<String> apiPostPath;

    @ApiModelProperty(value = "接口路径")
    private List<String> apiDeletePath;

    public Menu getMenu(){

        switch (this.type){
            case FOLDER:
                return Menu.builder()
                        .parentId(this.parentId)
                        .type(this.type)
                        .icon(this.icon)
                        .cache(this.cache)
                        .hidden(this.hidden)
                        .title(this.title)
                        .path(this.path)
                        .code(this.code)
                        .component(this.component)
                        .redirect(this.redirect)
                        .sort(this.sort)
                        .build();
            case MENU:
                return Menu.builder()
                        .parentId(this.parentId)
                        .type(this.type)
                        .icon(this.icon)
                        .cache(this.cache)
                        .hidden(this.hidden)
                        .title(this.title)
                        .path(this.path)
                        .code(this.code)
                        .component(this.component)
                        .apiPath(new ApiPath(getApiGetPath(),getApiPutPath(),getApiPostPath(),getApiDeletePath()))
                        .sort(this.sort)
                        .build();
            case BUTTON:
                return Menu.builder()
                        .parentId(this.parentId)
                        .type(this.type)
                        .title(this.title)
                        .code(this.code)
                        .apiPath(new ApiPath(getApiGetPath(),getApiPutPath(),getApiPostPath(),getApiDeletePath()))
                        .build();
        }
        return null;
    }
}
